/*
    created:2023/4/22   
    filename: Main.c
    author: 李东霖
    purpose：二叉排序树的数据结构和基本操作测试
*/
#include"BST.h"
int main()
{
    BSTree tree=0; // 声明树指针变量。
    ElemType arr[]={50,66,60,26,21,30,70,68}; 
    /*
    // 用数组arr中的序列构建二叉排序树TT。
    // 构建的二叉排序树将如下：
                50
              /    \
            26      66
           /   \    / \
          21   30  60  70
                      /
                     68
    */
    CreateBST(&tree,arr,sizeof(arr)/sizeof(ElemType));
    ElemType elem = 60;
    BSTNode* p = NULL;
    BSTNode* pp = NULL;
    p = Find(tree,&elem);
    pp = Find1(tree,&elem);
    printf("p->data = %d\npp->data %d\n",p->data,pp->data);
    InOrder(tree);
    printf("\n");
    printf("h = %d",TreeDepth(tree));
    printf("\n");
    elem = 100;
    Insert(&tree,&elem);
    InOrder(tree);
    printf("\n");
    printf("h = %d",TreeDepth(tree));
    printf("\n");
    elem = 67;
    Insert1(&tree,&elem);
    elem = 59;
    Insert1(&tree,&elem);
    InOrder(tree);
    printf("\n");
    printf("h = %d",TreeDepth(tree));
    printf("\n");
    InOrder(tree);
    printf("\n");

    // //删除
    elem = 60;
    Delete(&tree,&elem);
    InOrder(tree);
    printf("\n");
    printf("h = %d",TreeDepth(tree));
    printf("\n");

    elem = 66;
    Delete(&tree,&elem);
    InOrder(tree);
    printf("\n");
    printf("h = %d",TreeDepth(tree));
    printf("\n");

    elem = 21;
    Delete(&tree,&elem);
    InOrder(tree);
    printf("\n");
    printf("h = %d\n",TreeDepth(tree));



    //看排序
    PreOrder(tree);
    printf("\n");
    InOrder(tree);
    printf("In\n");
    PostOrder(tree);
    printf("\n");
    return 0;
}